package Test.jsp.common;

import java.io.File;
import java.io.FileWriter;

import Test.tools.Utils;


public class JSPLeftTemp {

	public static void jSPLeftTest(String programName,String tableString) throws  Exception{
		String rn = "\r\n";
	    String tablestr = tableString.substring(0,tableString.length()-1);
		String []array = Utils.stringToArray(tablestr);
		StringBuilder sbtrtd = new StringBuilder();
		for (int i = 0; i < array.length ; i++) {
			String trtd = 
			"       <TR>" + rn + 
			"        <TD height=\"10\"></TD></TR>" + rn + 
			"          <TR height=\"22\">" + rn + 
			"    <TD style=\"PADDING-LEFT: 15px\" background=\"<%=path %>/login_images/menu_bt.jpg\"><A " + rn + 
			"          class=menuParent " + rn + 
			"          href=\"/"+programName+"/"+array[i]+"View.do\" target=main>"+array[i]+"Manager</A></TD></TR>" + rn + 
			 rn ;
			sbtrtd.append(trtd);
		}
		String src = 
		
		"<%@ page language=\"java\"  import=\"java.util.*\" pageEncoding=\"UTF-8\"%>" + rn + 
		"<%@ taglib uri=\"http://java.sun.com/jsp/jstl/core\" prefix=\"c\"%>" + rn + 
		"<%@ taglib prefix=\"form\" uri=\"http://www.springframework.org/tags/form\" %>" + rn + 
		"<%@ taglib prefix=\"fmt\" uri=\"http://java.sun.com/jsp/jstl/fmt\" %>" + rn + 
		"<%@ taglib prefix=\"fn\" uri=\"http://java.sun.com/jsp/jstl/functions\" %>" + rn + 
		"<%" + rn + 
		"String path = request.getContextPath();" + rn + 
		"String basePath = request.getScheme()+\"://\"+request.getServerName()+\":\"+request.getServerPort()+path+\"/\";" + rn + 
		"%>" + rn + 

		"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">" + rn + 
		"<html>" + rn + 
		"  <head>" + rn + 
		"    <base href=\"<%=basePath%>\">" + rn + 
		    
		"    <title>leftFrame</title>" + rn + 
		"  </head>" + rn + 
		"  <body bgcolor=\"#F0F9FD\">" + rn + 


		
		"  <TABLE height=\"100%\" cellSpacing=\"0\" cellPadding=\"0\" width=\"170\" background=\"<%=path %>/login_images/menu_bg.jpg\" border=0>" + rn + 
		"    <TR>" + rn + 
		"     <TD vAlign=top align=\"center\">" + rn + 
		"    <TABLE cellSpacing=\"0\" cellPadding=\"0\" width=\"150\" border=\"0\">" + rn + 
	        
		sbtrtd +
	            
		"          <TR height=22>" + rn + 
		"   	 <TD style=\"PADDING-LEFT: 15px\">" + rn + 
		"    	</TD></TR>  	" + rn + 
	            
		"     </TABLE>" + rn + 

	          
		"    </TD>" + rn + 
		"    </TR></TABLE>" + rn + 
		
		"  </body>" + rn + 
		rn + 
		"</html>" + rn + 
		rn;
		
		String path = System.getProperty("user.dir")+"/WebRoot/back/jsp/";
		String fileName = System.getProperty("user.dir")+"/WebRoot/back/jsp/left.jsp";
		File fpath = new File(path);
		if (!fpath.exists()) {
		   fpath.mkdirs();
	    }
		File f = new File(fileName);
		FileWriter fw = new FileWriter(f);
		fw.write(src);
		fw.flush();
		fw.close();
 }	
}
